// myDate.getYear();        //获取当前年份(2位)

// myDate.getFullYear();    //获取完整的年份(4位,1970-????)

// myDate.getMonth();       //获取当前月份(0-11,0代表1月)

// myDate.getDate();        //获取当前日(1-31)

// myDate.getDay();         //获取当前星期X(0-6,0代表星期天)

// myDate.getTime();        //获取当前时间(从1970.1.1开始的毫秒数)

// myDate.getHours();       //获取当前小时数(0-23)

// myDate.getMinutes();     //获取当前分钟数(0-59)

// myDate.getSeconds();     //获取当前秒数(0-59)

// myDate.getMilliseconds();    //获取当前毫秒数(0-999)

// myDate.toLocaleDateString();     //获取当前日期

// var mytime=myDate.toLocaleTimeString();     //获取当前时间

// myDate.toLocaleString( );        //获取日期与时间
const app = getApp()
var time_data = {
  // day
  js_date_time: function (unixtime, type) {
    var date = new Date(unixtime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    // return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;//年月日时分秒
    if (type == 1) {
      return y + '-' + m + '-' + d
    } else if (type == 2) {
      return h + ':' + minute
    } else {
      return y + '/' + m + '/' + d + ' ' + h + ':' + minute
    }
  },
  // 获取当期时间
  data_time: function (type,num) {
    var myDate = new Date()
    var Month = (myDate.getMonth() + 1)<10?'0'+(myDate.getMonth() + 1):(myDate.getMonth() + 1)
	var date=myDate.getDate()<10?'0'+myDate.getDate():myDate.getDate()
    var time
    if(type==1){
      time = myDate.getFullYear() + "-" + Month + "-" + date
    }else{
      var timer = myDate.getFullYear() + "-" + Month + "-" + date
      timer.replace(/-/g, '/')
      let dd = new Date(timer)
      let td = dd.getTime(dd)
      let map=td+3600*1000*24*num
      var date = new Date(map);
      var y = date.getFullYear();
      var m = date.getMonth() + 1;
      m = m < 10 ? ('0' + m) : m;
      var d = date.getDate();
      d = d < 10 ? ('0' + d) : d;
      var h = date.getHours();
      h = h < 10 ? ('0' + h) : h;
      var minute = date.getMinutes();
      var second = date.getSeconds();
      minute = minute < 10 ? ('0' + minute) : minute;
      second = second < 10 ? ('0' + second) : second;
      var timeStr = y + '-' + m + '-' + d;
      time=timeStr
    }
    return time
  },
  // 当前小时
  new_hours: function (date) {
    if(date){
		var myDate = new Date(date.replace(/-/g,'/'));
	}else{
		var myDate = new Date();
	}
    var time = {
      start_time: "",
      end_time: "",
    }
    if (myDate.getMinutes() >= 0 && myDate.getMinutes() <30) {
      time.start_time = myDate.getHours() + ":" + "00"
      time.end_time = myDate.getHours()+1 + ":" + "00"
    }else {
      time.start_time = myDate.getHours() +":" + "30"
      time.end_time = myDate.getHours() + 1 + ":" + "30"
    }
    var date=time
    if(date.start_time.split(":")[0]<10){
      var hour="0"+date.start_time.split(":")[0]
      time.start_time=hour+":"+date.start_time.split(":")[1]
    }
    if(date.end_time.split(":")[0]<10){
      var hour="0"+date.end_time.split(":")[0]
      time.end_time=hour+":"+date.end_time.split(":")[1]
    }
    if(time.end_time == "08:00" ||time.end_time == "07:30" || time.end_time=="07:00" ||time.end_time=="06:30"||time.end_time== "06:00"||time.end_time== "05:30"||time.end_time== "05:00"||time.end_time== "04:30"||time.end_time== "04:00"||time.end_time== "03:30"||time.end_time== "03:00"||time.end_time== "02:30"||time.end_time== "02:00"||time.end_time== "01:30"||time.end_time== "01:00"||time.end_time== "00:30"||time.end_time== "00:00"){
     // time.end_time = "08:30"
     // time.start_time = "08:00"
    }else if(time.end_time == "23:30" ||time.end_time == "24:00"){
      // time.end_time = "23:00"
      // time.start_time = "23:00"
    }
    return time
  },
  // 转换日期格式
  formatTime: function (number, format) {
    var formateArr = ['Y', 'M', 'D', 'h', 'm', 's'];
    var returnArr = [];

    var date = new Date(number * 1000);
    returnArr.push(date.getFullYear());
    returnArr.push(date.getMonth() + 1);
    returnArr.push(date.getDate());

    returnArr.push(date.getHours());
    returnArr.push(date.getMinutes());
    returnArr.push(date.getSeconds());

    for (var i in returnArr) {
      format = format.replace(formateArr[i], returnArr[i]);
    }
    return format;
  },
  time_to_sec: function (time, type) {
    var z
    if (type == 1) {
      var t = parseInt(app.globalData.se_time.start_hours) * 3600
      var m = parseInt(app.globalData.se_time.start_minutes) * 60
      z = t + m
    } else {
      var t = parseInt(app.globalData.se_time.end_hours) * 3600
      var m = parseInt(app.globalData.se_time.end_minutes) * 60
      z = t + m
    }
    return z
  },
  // 时分转换
  hm: function (dara) {
    var theTime = dara //时间戳(秒)
    var minute = 0; // 分
    var hour = 0;//小时
    if (theTime > 60) {
      minute = parseInt(theTime / 60);
      theTime = parseInt(theTime % 60);
      if (minute > 60) {
        hour = parseInt(minute / 60);
        minute = parseInt(minute % 60);
      }
    }
    var result = "" + parseInt(theTime) + "秒"
    if (minute > 0) {
      result = "" + parseInt(minute) + "分" + result;
    }
    if (hour > 0) {
      result = "" + parseInt(hour) + "小时" + result;
    }
    return result
  },
  hm_hours: function (dara) {
    var theTime = dara //时间戳(秒)
    var minute = 0; // 分
    var hour = 0;//小时
    if (theTime > 60) {
      minute = parseInt(theTime / 60);
      theTime = parseInt(theTime % 60);
      if (minute > 60) {
        hour = parseInt(minute / 60);
        minute = parseInt(minute % 60);
      }
    }
    var result
    if (minute > 0 && minute <60) {
      result=hour+"."+5
    }else if(minute == 60){
      result=1
    }else{
      result=hour
    }
    // if (hour > 0) {
    //   result = "" + parseInt(hour) + "小时" + result;
    // }

    return result
  },
  getZero: function (num) {
    // 单数前面加0
    if (parseInt(num) < 10) {
      num = '0' + num;
    }
    return num;
  },
  // 年月日转换时间戳
  nyr: function (data) {
    let p = data.replace(/-/g, '/')
    let d = new Date(p)
    let t = d.getTime(d)
    return t / 1000
  },
  dateToTimestamp: function (dateStr) {
    if (!dateStr) {
      return ''
    }
    let newDataStr = dateStr.replace(/\.|\-/g, '/')
    let date = new Date(newDataStr);
    let timestamp = date.getTime();
    return timestamp
  },
  stamp_time:function(data){
    var number=data.split(":")
    var stamp=parseInt(number[0])*3600+parseInt(number[1])*60
    return stamp
  },
  // 加时间
  time_to(time) {
    　　if (time !== null) {
    　　　　var s = "";
    　　　　var hour = time.split(":")[0];
    　　　　var min = time.split(":")[1];
    　　　　if(min==30){
                if(hour<10){
                  s= hour+1 + ":" + "00"
                }else{
                  s= parseFloat(hour)+parseFloat(1) + ":" + "00"
                }
            }else{
              s= hour + ":" + "30"
            }
            return s
    　　}
    },
    // 时分转换时间戳
    time_to_secc(time) {
      　　if (time !== null) {
      　　　　var s = "";
      　　　　var hour = time.split(":")[0];
      　　　　var min = time.split(":")[1];
      　　　　s = Number(hour * 3600) + Number(min * 60);
      　　　　return s;
      　　}
    },
    // 4小时,全天
    time_to_list(val,endd,type) {
          var stmap = {
            end_time:"",
            end_stmap:""
          }
          var add_time=val
          var end_time=endd
          var add_hour 
          var add_min = add_time.split(":")[1];
          var add_stmap
          var end_hours = end_time.split(":")[0];
          var end_min = end_time.split(":")[1];
          var end_stmap = Number(end_hours * 3600) + Number(end_min * 60);
          if(type==0){
            add_hour = parseFloat(add_time.split(":")[0])+parseFloat(4);
          }else if(type==1){
            add_hour = parseFloat(add_time.split(":")[0])+parseFloat(8);
          }else if(type==4){
            add_hour = parseFloat(add_time.split(":")[0])+parseFloat(2);
          }else if(type==3){
            add_hour = parseFloat(add_time.split(":")[0])+parseFloat(6);
          }
          add_stmap = Number(add_hour * 3600) + Number(add_min * 60);
          if(add_stmap<end_stmap){
            stmap.end_time = add_hour + ":" + add_min
            stmap.end_stmap = add_stmap
          }else{
            stmap.end_time = endd
            stmap.end_stmap = end_stmap
          }
          return stmap
    },
}
module.exports = time_data